<div id="login-form">
    <div id="csdata-messages"> </div>
    <form id="csdataForm">
        <h3>Cs Data form</h3>
        <div>
            
        <p><label>Data</label></p>
        <p>


            <textarea name="data"  id="data"           
                    cols="80"
                    rows="20">
            </textarea><p>
       
        
        <div>
            <input type="button" value="SaveData" onclick="onUpdate()" />
            <input type="button" value="CreateData" onclick="generateData()" />
        </div>    
    </form>
</div>

<div style="clear:both"> </div>

<script type="text/javascript">

$(function(){
	Vosao.initJSONRpc(loadData);
});
function loadData() {
	Vosao.jsonrpc.csdataFrontService.getCsdataUser(function (r) {
		if (r){
			if (r.data){
				$('#data').val(r.data);
			}
		}
    });
}




function registerValidate(vo) {
	if (!vo.data) {
        return "Data is empty";
    }/*
	if (!vo.name) {
		return "Name is empty";
	}
    
    if (!vo.password1) {
        return "Password is empty";
    }
    if (vo.password1 != vo.password2) {
        return "Passwords don't match";
    }*/
}


function onUpdate() {
    var vo = {
    	data : $('#data').val(),
        //name : $('#name').val(),
        //password1 : $('#password1').val(),
        //password2 : $('#password2').val()
    };
    var error = registerValidate(vo);
    if (error) {
        registerError(error);
    }
    else {
        Vosao.jsonrpc.csdataFrontService.register(function (r, e) {
            if (Vosao.serviceFailed(e)) return;
            if (r.result == 'success') {
                registerInfo('Success. Data saved.');
                $('#csdataForm').hide();
            }
            else {
                 registerError(r.message);
            }
        }, Vosao.javaMap(vo),'', '');
    }                
}

function registerError(msg) {
    $('#register-messages').html('<span class="error">' + msg + '</span>');
}

function registerInfo(msg) {
    $('#register-messages').html('<span class="info">' + msg + '</span>');
}
function generateData(){
	var example_xml = " <?xml version=\"1.0\" encoding=\"UTF-8\"?> " +
			"<cspl id=\"\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" "+ 
			"xsi:noNamespaceSchemaLocation=\"cs_personal.xsd\"> "+
			"<personaldetails AIM_screenname=\"\" Jabber_screenname=\"\" YIM_screenname=\"\" city=\"cityName\" country_name=\"CountryName\" email=\"\" family_name=\"\" given_name=\"\" "+
			"middle_name=\"\" organization=\"\" phone=\"\" photo_url=\"\" postal_code=\"\" state_province=\"\" street=\"\" tags=\"\" url=\"\"></personaldetails> <contractdetails alta=\"2010-02-09\" bill_on=\"1\" plan=\"start\" previous_plan=\"\"/> <booking TZ=\"+2\" car_id=\"2\" description=\"Desciption\" destination_trip=\"\" end=\"2010-10-18T16:00:00\" parking_id=\"1124\" start=\"2010-10-18T20:00:00\" tags=\"\" url_parking_car_description=\"http://www.fundaciomobiltatsostenible.org/momo/cs/avancar.xml\"></booking> "+
			"<statistics kilometers=\"0.0\"/> 	</cspl> " ;
			
	$('#data').val(example_xml);
}
</script>
